package com.ssy.lingxi.product.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.request.warehouse.*;
import com.ssy.lingxi.product.api.model.response.warehouse.*;
import com.ssy.lingxi.product.service.FreightSpaceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu APP-仓位管理-仓位库存管理
 * @author wrc
 * @date 2020/7/20
 */
@RestController
@RequestMapping("/product/mobile")
public class MobileFreightSpaceController extends BaseController {
    @Resource
    FreightSpaceService freightSpaceService;

    @ApiOperation(value = "仓位库存列表查询")
    @GetMapping("/freight/space/list")
    public Wrapper<PageData<FreightSpaceListResponse>> freightSpaceList(FreightSpaceListRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceList(request, sysUser);
    }

    /**
     * 仓位管理-查询全部仓位
     * @author wrc
     * @date 2020/8/7
     */
    @ApiOperation(value = "查询全部仓位")
    @GetMapping("/freight/space/all")
    public Wrapper<List<FreightSpaceListResponse>> freightSpaceAll() {
        return freightSpaceService.freightSpaceAll();
    }

    @ApiOperation(value = "仓位库存停用&启用")
    @PostMapping("/freight/space/stop/start")
    public Wrapper freightSpaceStopRoStart(@Validated @RequestBody FreightSpaceStopRoStartRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceStopRoStart(request, sysUser);
    }

    @ApiOperation(value = "仓位库存添加")
    @PostMapping("/freight/space/add")
    public Wrapper freightSpaceAdd(@Validated @RequestBody FreightSpaceAddRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceAdd(request, sysUser);
    }

    @ApiOperation(value = "仓位库存信息修改")
    @PostMapping("/freight/space/updata")
    public Wrapper freightSpaceUpdatat(@Validated @RequestBody FreightSpaceUpdataRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceUpdatat(request, sysUser);
    }

    @ApiOperation(value = "仓位库存详情")
    @GetMapping("/freight/space/details")
    public Wrapper<FreightSpaceDetailsResponse> freightSpaceDetails(FreightSpaceDetailsRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceDetails(request, sysUser);
    }

    @ApiOperation(value = "仓位库存调拨-调出")
    @PostMapping("/freight/space/allot/export")
    public Wrapper<FreightSpaceAllotFoldResponse> freightSpaceAllotExport(@RequestBody FreightSpaceAllotRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceAllotExport(request, sysUser);
    }

    @ApiOperation(value = "仓位库存调拨-调入")
    @PostMapping("/freight/space/allot/fold")
    public Wrapper<FreightSpaceAllotFoldResponse> freightSpaceAllotFold(@RequestBody FreightSpaceAllotRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceAllotFold(request, sysUser);
    }

    @ApiOperation(value = "仓位库存调拨记录")
    @GetMapping("/freight/space/allot/fold/log")
    public Wrapper<PageData<FreightSpaceAllotLogListResponse>> freightSpaceAllotFoldLog(FreightSpaceAllotLogListRequest request) {
        return freightSpaceService.freightSpaceAllotFoldLog(request);
    }

    @ApiOperation(value = "根据仓位ID查询仓位绑定的会员")
    @GetMapping("/freight/space/mamber/list")
    public Wrapper<PageData<ApplyMemberRequest>> freightSpaceMamberList(FreightSpaceAllotLogListRequest request) {
        return freightSpaceService.freightSpaceMamberList(request);
    }

    @ApiOperation(value = "根据仓位库存和商品ID查询仓位库存列表")
    @GetMapping("/freight/space/list/by/productid")
    public Wrapper<List<FreightSpaceProductIdListResponse>> freightSpaceByProductId(FreightSpaceProductIdListRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.freightSpaceByProductId(request, sysUser);
    }

    @ApiOperation(value = "扣除库存")
    @PostMapping("/deduct/inventory")
    public Wrapper<Void> deductInventory(@RequestBody InventoryByProductIdRequest request) {
        return freightSpaceService.deductInventory(request);
    }

    @ApiOperation(value = "返回库存")
    @PostMapping("/deduct/return")
    public Wrapper<Void> deductReturn(@RequestBody InventoryByProductIdRequest request) {
        return freightSpaceService.deductReturn(request);
    }

    @ApiOperation(value = "根据商品ID查询仓位扣减记录")
    @GetMapping("/position/deduction/record/list")
    public Wrapper<PageData<PositionInventoryDeductionRecordResponse>> positionDeductionRecordList(PositionInventoryDeductionRecordRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.positionDeductionRecordList(sysUser, request);
    }

    @ApiOperation(value = "根据商品ID查询仓位扣减记录-平台后台")
    @GetMapping("/platform/position/deduction/record/list")
    public Wrapper<PageData<PositionInventoryDeductionRecordResponse>> platformPositionDeductionRecordList(PositionInventoryDeductionRecordRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.platformPositionDeductionRecordList(sysUser, request);
    }

    /**
     *查询商品的仓位库存
     */
    @GetMapping("/stock/byProductId")
    public Wrapper<Double> stockByProductId(StockByProductIdRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return freightSpaceService.stockByProductId(request, sysUser);
    }

    /**
     *查询商品的仓位库存-内部
     */
    @GetMapping("/stock/byProductId/inside")
    public Wrapper<Double> stockByProductIdInside(@RequestParam("productId") Long productId, @RequestParam("shopId") Long shopId, @RequestParam("memberId") Long memberId, @RequestParam("memberRoleId") Long memberRoleId) {
        return freightSpaceService.stockByProductIdInside(productId, shopId, memberId, memberRoleId);
    }
}
